package com.ysg.widget.code;

import android.content.Context;
import android.util.AttributeSet;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.ysg.R;
import com.ysg.widget.time.TimeCountDown;

public class YCode extends RelativeLayout {
    public interface OnCodeClickListener{
        void onCodeClick();
    }

    private OnCodeClickListener listener;
    public void setOnCodeClickListener(OnCodeClickListener listener){
        this.listener = listener;
    }

    private TextView tvCode;
    private TimeCountDown time;

    public YCode(Context context) {
        super(context);
    }

    public YCode(Context context, AttributeSet attrs) {
        super(context, attrs);
        View view = View.inflate(context, R.layout.widget_code, this);
        tvCode = view.findViewById(R.id.tvCode);

        time = new TimeCountDown(60000, 1000, tvCode);

        tvCode.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                if (listener!=null){
                    listener.onCodeClick();
                }
            }
        });
    }

    public void startTimeCountDown(){
        if (null != time){
            time.start();
        }
    }



}
